<?php
namespace  Admin\Controller;
class TagController extends  AuthController{
    /*
     * 标签管理
     * */
    public  function index(){
        $this->tags=M('Tag')->order('tid desc')->field('tid,tname')->select();
        //p($this->tags);die();
        $this->display();
    }
    /*分配添加页面
    */
    public  function add(){
        $this->page_title="خەتكۈچ قۇشۇش";
        $this->display();
    }

    /*
     * 处理添加页面发送的数据
     * */
    public function addHandler(){
       $rules=array(
            array('tname','require','标签名必须'),
        );
        if(!M('Tag')->validate($rules)->create())  $this->error(M('Tag')->getError());
        if(!M('Tag')->add()) $this->error('添加失败');
        $this->success('添加成功',U('Tag/index'));
       // $this->display();
    }

    /*
     * 删除标签
     * */
    public function delete($tid){
     if(M('Tag')->where(array('tid'=>$tid))->delete())
     {
         $data=['status'=>1,'message'=>'ئۈچۈرۈش مۇۋاپىقىيەتلىك بولدى'];
     }else{
         $data=['status'=>0,'message'=>'ئۈچۈرىش مەغلۇب بولدى'];
     }
     $this->ajaxReturn($data);
    }
    /*
     *编辑标签
     * */
    public function edit($tid)
    {
        $this->page_title="خەتكۈچ تەھرىرلەش";
        $this->tags=M('Tag')->where(array('tid'=>$tid))->find();
        $this->display();
    }
    /*
     * 处理编辑页面发送的数据
     * */
    public function saveHandler(){
        /*p($_POST);
        die();*/
        if(!M('Tag')->save(I('post.'))) $this->error('编辑失败');
            $this->success('编辑成功', U('Tag/index'));

        }
}